/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.forms;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author navneet
 */
public class LAFB extends org.apache.struts.validator.ValidatorActionForm {
    
    private String userId;
    private String password;
    private String j_captcha_response;
    private String error;

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public String getJ_captcha_response() {
        return j_captcha_response;
    }

    public void setJ_captcha_response(String j_captcha_response) {
        this.j_captcha_response = j_captcha_response;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public LAFB() {
        super();
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request){
        userId              =   "";
        password            =   "";
        j_captcha_response  =   "";
    }
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        HttpSession session = request.getSession();
        if (getUserId() == null || getUserId().length() < 1) {
            errors.add("userId", new ActionMessage("error.LAFB.userId.required"));
        }
        if (getPassword() == null || getPassword().length() < 1) {
            errors.add("password", new ActionMessage("error.LAFB.password.required"));
        }
        if (getJ_captcha_response() == null || getJ_captcha_response().length() < 1) {
            errors.add("j_captcha_response", new ActionMessage("error.LAFB.j_captcha_response.required"));
        }
        if (!getJ_captcha_response().equals((String) session.getAttribute("CAPTCHA_KEY"))) {
            errors.add("j_captcha_response", new ActionMessage("error.LAFB.j_captcha_response.notMatch"));
        }
        return errors;
    }
}
